#include <iostream>
#include <string>
#include <vector>

int compare(std::vector<int> s1_cnt, std::vector<int> s2_cnt)
{
    int flag = 1;
    for (int i = 0; i < 26; i++)
    {
        if (s1_cnt[i] > s2_cnt[i])
        {
            flag = 0;
            break;
        }
    }
    return flag;
}

int main()
{
    std::string s1, s2;
    int k;
    std::cin >> s1;
    std::cin >> s2;
    std::cin >> k;

    std::vector<int> s1_cnt(26, 0);
    std::vector<int> s2_cnt(26, 0);

    for (int i = 0; i < s1.size(); i++)
    {
        s1_cnt[s1[i] - 'a']++;
    }

    int sub_len = s1.size() + k;
    for (int j = 0; j < sub_len; j++)
    {
        s2_cnt[s2[j] - 'a']++;
    }

    int ret = compare(s1_cnt, s2_cnt);
    if (ret)
    {
        std::cout << 0 << std::endl;
    }
    else
    {
        bool find = false;
        for (int i = sub_len; i < s2.size(); i++)
        {
            s2_cnt[i - sub_len]--;
            s2_cnt[i]++;

            int ret = compare(s1_cnt, s2_cnt);
            if (ret)
            {
                find = true;
                std::cout << i - sub_len << std::endl;
                break;
            }
        }

        if (!find)
        {
            std::cout << -1 << std::endl;
        }
    }

    return 0;
}